﻿#include "printsettingwidget.h"
#include "ui_printsettingwidget.h"
#include <QMessageBox>

PrintSettingWidget::PrintSettingWidget(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PrintSettingWidget)
{
    ui->setupUi(this);
    setWindowTitle("打印设置");
}

PrintSettingWidget::~PrintSettingWidget()
{
    delete ui;
}

void PrintSettingWidget::setSettingKey(QString settingKey){
    printSetting.setSettingKey(settingKey);
    printSetting.load();

    ui->lineEditTitle->setText(printSetting.title);
    ui->lineEditPaperWidth->setText(QString("%1").arg(printSetting.paperWidth));
    ui->lineEditPaperHeight->setText(QString("%1").arg(printSetting.paperHeight));
    ui->comboBoxHeaderItem1->setCurrentText(printSetting.headerItem1);
}

PrintSetting* PrintSettingWidget::getPrintSetting(){
    return &printSetting;
}

void PrintSettingWidget::on_pushButtonCancel_clicked()
{
    this->close();
}

void PrintSettingWidget::on_pushButtonSave_clicked()
{
    printSetting.title = ui->lineEditTitle->text();
    printSetting.paperWidth = ui->lineEditPaperWidth->text().toInt();
    printSetting.paperHeight = ui->lineEditPaperHeight->text().toInt();
    printSetting.save();

    QMessageBox::information(this, "提示", "保存成功");
}

QString PrintSettingWidget::getComboboxValue(QComboBox *combox){
    if(combox->currentIndex()==0){
        return "";
    }

    return combox->currentText();
}

void PrintSettingWidget::on_comboBoxHeaderItem1_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem1 = getComboboxValue(ui->comboBoxHeaderItem1);
}

void PrintSettingWidget::on_comboBoxHeaderItem2_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem2 = getComboboxValue(ui->comboBoxHeaderItem2);
}

void PrintSettingWidget::on_comboBoxHeaderItem3_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem3 = getComboboxValue(ui->comboBoxHeaderItem3);
}

void PrintSettingWidget::on_comboBoxHeaderItem4_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem4 = getComboboxValue(ui->comboBoxHeaderItem4);
}

void PrintSettingWidget::on_comboBoxHeaderItem5_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem5 = getComboboxValue(ui->comboBoxHeaderItem5);
}

void PrintSettingWidget::on_comboBoxHeaderItem6_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem6 = getComboboxValue(ui->comboBoxHeaderItem6);
}

void PrintSettingWidget::on_comboBoxHeaderItem7_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem7 = getComboboxValue(ui->comboBoxHeaderItem7);
}

void PrintSettingWidget::on_comboBoxHeaderItem8_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem8 = getComboboxValue(ui->comboBoxHeaderItem8);
}

void PrintSettingWidget::on_comboBoxHeaderItem9_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem9 = getComboboxValue(ui->comboBoxHeaderItem9);
}

void PrintSettingWidget::on_comboBoxHeaderItem10_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.headerItem10 = getComboboxValue(ui->comboBoxHeaderItem10);
}

void PrintSettingWidget::on_comboBoxTailItem1_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem1 = getComboboxValue(ui->comboBoxTailItem1);
}

void PrintSettingWidget::on_comboBoxTailItem2_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem2 = getComboboxValue(ui->comboBoxTailItem2);
}

void PrintSettingWidget::on_comboBoxTailItem3_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem3 = getComboboxValue(ui->comboBoxTailItem3);
}

void PrintSettingWidget::on_comboBoxTailItem4_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem4 = getComboboxValue(ui->comboBoxTailItem4);
}

void PrintSettingWidget::on_comboBoxTailItem5_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem5 = getComboboxValue(ui->comboBoxTailItem5);
}

void PrintSettingWidget::on_comboBoxTailItem6_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem6 = getComboboxValue(ui->comboBoxTailItem6);
}

void PrintSettingWidget::on_comboBoxTailItem7_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem7 = getComboboxValue(ui->comboBoxTailItem7);
}

void PrintSettingWidget::on_comboBoxTailItem8_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem8 = getComboboxValue(ui->comboBoxTailItem8);
}

void PrintSettingWidget::on_comboBoxTailItem9_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem9 = getComboboxValue(ui->comboBoxTailItem9);
}

void PrintSettingWidget::on_comboBoxTailItem10_currentIndexChanged(int index)
{
    Q_UNUSED(index);
    printSetting.tailItem10 = getComboboxValue(ui->comboBoxTailItem10);
}
